import java.util.Scanner;

public class AddressList {

	public static void main(String[] args) {

		OrderedLinkedList<String> oll = new OrderedLinkedList<String>();
		Scanner keybd = new Scanner(System.in);
		String key = "";
		String number = "";
		String returnValue = "";

		System.out.println("Starting program, the address book is empty.");
		while(!key.equalsIgnoreCase("quit")) {
			System.out.print("Please enter one of the following [add, find, print, quit]: ");
			key = keybd.nextLine();
			
			if(key.equalsIgnoreCase("add")) {
				System.out.print("Please enter a name to add: ");
				key = keybd.nextLine(); //String key for the object
				
				System.out.print("Please enter a telephone number for " + key + ": ");
				number = keybd.next(); //Object for the String key
				
				//If it's null, the add was successful.
				returnValue = oll.add(key, number);  

				//Print this out regardless if returnValue is null or not.
				System.out.println(key + " was added to the address book with phone number: " + number);
				if(returnValue != null) {
					//An object was returned which means there was a previous key with the same key value.
					//Print out what the old value was.
					System.out.println("Previous phone number for " + key + " was: " + returnValue);
				}
				keybd.nextLine(); //Eat the buffer
				
			} else if(key.equalsIgnoreCase("find")) {
				System.out.print("Please enter a name to search for: ");
				key = keybd.nextLine(); //String key to search for in the OrderedLinkedList.
				
				returnValue = oll.find(key);

				if(returnValue == null) {
					//The key was not found in the linked list, therefore returned null.
					System.out.println(key + " was not found in the address book.");
				} else {
					//The key was found and returned the object.
					System.out.println(key + "'s phone number is: " + returnValue);
				}
				
			} else if (key.equalsIgnoreCase("print")) {
				//Print the contents of the OrderedLinkedList.
				oll.print();
			}
			
			//Print after each interaction to show how many items are in the OrderedLinkedList.
			System.out.println("The address book has " + oll.size() + " entries.");
		}
		
		System.out.println("Goodbye!");
		keybd.close(); //Close buffer.
	}

}
